﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using NPOI.HSSF.UserModel;
using NPOI.HPSF;
using NPOI.POIFS.FileSystem;
using System.Drawing;
using NPOI.SS.UserModel;
using IHISCETeim.Model;
using System.Reflection;
using System.IO;
using NPOI.SS.Util;

namespace IHISCETeim.Web.Export.MacModel
{
    public partial class OFactoryRenovationSing : ExportPageBase
    {
        protected override string xlsTemplateFileName
        {
            get
            {               
                return "厂内翻新机管制票.xls";
            }
        }
        protected override string SheetName
        {
            get
            {
                return "翻新机管制票";
            }
        }

        protected int ID
        {
            get
            {
                return GetRequestValue<int>("ID", 0);
            }
        }

        protected OFactoryRenovationInfo objprod = null;
        protected OFactoryRenovationInfo ObjProd
        {
            get
            {
                if (objprod == null)
                {
                    objprod = OFactoryRenovationController.GetList(ID);
                }
                return objprod;
            }
        }
        

        protected void Page_Load(object sender, EventArgs e)
        {
            InitializeWorkbook();
            ISheet sheet1 = hssfworkbook.GetSheet(SheetName);

            sheet1.GetRow(1).GetCell(7).SetCellValue(ObjProd.SerialNumber);
            sheet1.GetRow(1).GetCell(9).SetCellValue(ObjProd.DocNum);
            sheet1.GetRow(2).GetCell(7).SetCellValue(ObjProd.WorkTime);
            sheet1.GetRow(2).GetCell(9).SetCellValue(ObjProd.IssueDate.ToString("yyyy-MM-dd"));
            sheet1.GetRow(3).GetCell(3).SetCellValue(ObjProd.DemandDept);
            sheet1.GetRow(3).GetCell(6).SetCellValue(ObjProd.MachineProperty);
            sheet1.GetRow(3).GetCell(9).SetCellValue(ObjProd.IsCharges?"收费":"免费");
            sheet1.GetRow(4).GetCell(6).SetCellValue(ObjProd.AgentName);
            sheet1.GetRow(4).GetCell(9).SetCellValue((ObjProd.ReturnDate == DateTime.MinValue )? "" : ObjProd.ReturnDate.ToString("yyyy-MM-dd"));
            sheet1.GetRow(5).GetCell(3).SetCellValue(ObjProd.RenovationContent);
            sheet1.ForceFormulaRecalculation = true;
            WriteToFile();
        }

        protected override string GetXlsFileName(string oldFileName)
        {
            //return base.GetXlsFileName(oldFileName);

            return string.Format("{0}{1}.xls", "厂内翻新机管制票", ObjProd.DocNum).Trim();
        }
    }
}